package com.ibeetl.admin.api.web;

import com.ibeetl.admin.api.entity.Travel_attractions;
import com.ibeetl.admin.api.entity.Travel_attractions_line;
import com.ibeetl.admin.api.service.TravelAttractionsLineService;
import com.ibeetl.admin.api.service.TravelAttractionsService;
import com.ibeetl.admin.core.web.JsonResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@RestController
@Tag(
        name = "TravelAttractionsController")
public class TravelAttractionsController {

    private final Log log = LogFactory.getLog(this.getClass());
    private static final String MODEL = "/api/travel_attractions";
    @Resource
    private TravelAttractionsService travelAttractionsService;

    @Operation(
            summary = "新增景点"
    )
    @PostMapping(MODEL + "/add.json")
    @CrossOrigin
    public JsonResult<Travel_attractions> add(Travel_attractions travel_attractions) {
        if(travel_attractions.getUserId() == null){
            return JsonResult.failMessage("导游ID不可为空");
        }
        travel_attractions.setCreateDt(new Date());
        if(travelAttractionsService.save(travel_attractions)){
            Long attsId = travelAttractionsService.queryNewIdByUserId(travel_attractions.getUserId());
            travel_attractions.setAttsId(attsId);
            return JsonResult.success(travel_attractions);
        }else{
            return JsonResult.failMessage("新增失败！");
        }

    }
    @Operation(
            summary = "更新景点"
    )
    @PostMapping(MODEL + "/update.json")
    @CrossOrigin
    public JsonResult<Travel_attractions> update(Travel_attractions travel_attractions) {
        travel_attractions.setUpdateDt(new Date());
        travelAttractionsService.update(travel_attractions);
        return JsonResult.success(travel_attractions);
    }
    @Operation(
            summary = "删除景点"
    )
    @PostMapping(MODEL + "/deleteById.json")
    @CrossOrigin
    public JsonResult<Travel_attractions> deleteById(long attsId) {
        travelAttractionsService.delete(attsId,0);
        return JsonResult.success();
    }
    @Operation(
            summary = "根据景点ID查询景点"
    )
    @PostMapping(MODEL + "/queryById.json")
    @CrossOrigin
    public JsonResult<Travel_attractions> queryById(long attsId) {
        Travel_attractions  travel_attractions  = travelAttractionsService.queryById(attsId);
        return JsonResult.success(travel_attractions);
    }
    @Operation(
            summary = "根据导游ID查询景点"
    )
    @PostMapping(MODEL + "/queryByUserId.json")
    @CrossOrigin
    public JsonResult<List> queryByUserId(long userId) {
        List<Travel_attractions>  travel_attractions_list  = travelAttractionsService.queryByUserId(userId);
        return JsonResult.success(travel_attractions_list);
    }
    @Operation(
            summary = "根据景点路线ID查询景点"
    )
    @PostMapping(MODEL + "/queryByAttractionId.json")
    @CrossOrigin
    public JsonResult<List> queryByAttractionId(Long attractionId) {
        List<Travel_attractions>  travel_attractions_list  = travelAttractionsService.queryByAttractionId(attractionId);
        return JsonResult.success(travel_attractions_list);
    }


}
